package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.util.utils.Sundry;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.RedPacketsModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/30.
 */

public class RedPacketsActivityAdapter extends BaseAdapter {

    private Context mContext;
    List<RedPacketsModel> model= new ArrayList<>();
    public RedPacketsActivityAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem( List<RedPacketsModel> model){

        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_red_packets, null);
            holder.item_number = (TextView) convertView
                    .findViewById(R.id.item_number);
            holder.item_title = (TextView) convertView
                    .findViewById(R.id.item_title);

            holder.item_time = (TextView) convertView
                    .findViewById(R.id.item_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        RedPacketsModel redPacketsModel = model.get(position);
        holder.item_title.setText(redPacketsModel.getRedenvelopes());
//        if (redPacketsModel.getRedenvelopes().equals("2")){
//            holder.item_title.setText("抢到红包");
//        }else if (redPacketsModel.getRedenvelopes().equals("3")){
//            holder.item_title.setText("活动红包");
//        }else if (redPacketsModel.getRedenvelopes().equals("4")){
//            holder.item_title.setText("转入余额");
//        }else if (redPacketsModel.getRedenvelopes().equals("5")){
//            holder.item_title.setText("后台发放");
//        }
        holder.item_time.setText(Sundry.getStrsTime(redPacketsModel.getAddtimes()));
        if (redPacketsModel.getChangetype().equals("2")){
            holder.item_number.setText("+"+redPacketsModel.getAmountofmoney());
        }else {
            holder.item_number.setText("-"+redPacketsModel.getAmountofmoney());
        }

        return convertView;
    }

    class ViewHolder {
        TextView item_title;
        TextView item_time;
        TextView item_number;



    }
}

